package com.lemon.smartsafety.ui.adapter.apps;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.bind.BindInfoExtVo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.DateUtils;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class MyAppsAdapter extends LemonRcvAdapter<BindInfoExtVo> {
    private RecyclerTClickListener<BindInfoExtVo> mListener;

    public MyAppsAdapter(@Nullable List<BindInfoExtVo> data) {
        super(data);
    }

    public MyAppsAdapter(List<BindInfoExtVo> data, RecyclerTClickListener<BindInfoExtVo> listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new MyAppsItem();
    }

    public class MyAppsItem implements AdapterItem<BindInfoExtVo> {

        TextView tvTitle;
        TextView tvBindName;
        TextView tvStatus;
        TextView tvBindTime;


        private BindInfoExtVo mData;
        private int           mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_my_apps;
        }

        @Override
        public void bindViews(View root) {
            tvTitle = (TextView) root.findViewById(R.id.tv_title);
            tvBindName = (TextView) root.findViewById(R.id.tv_bind_name);
            tvStatus = (TextView) root.findViewById(R.id.tv_status);
            tvBindTime = (TextView) root.findViewById(R.id.tv_bind_time);
        }

        @Override
        public void setViews() {
        }

        @Override
        public void handleData(BindInfoExtVo data, int position) {
            mData = data;
            mPosition = position;

            tvTitle.setText(data.getApplicationTitle());
            tvBindName.setText(data.getBindName());
            if (StringUtils.getBoolean(data.getStatus())) {
                tvStatus.setText(StringUtils.getStatusString("已审核", StringUtils.ColorStatus.STATUS_GREEN));
            } else {
                tvStatus.setText(StringUtils.getStatusString("审核中", StringUtils.ColorStatus.STATUS_RED));
            }
            tvBindTime.setText(DateUtils.getFormatDateStringWithDateString(data.getBindDate(), DateUtils.dateFormatYMD));
        }
    }
}
